package nc.ui.arap.actions.edit;

import java.util.Iterator;
import java.util.List;

import nc.ui.cmp.workflow.IworkflowLinkData;
import nc.ui.pub.ClientEnvironment;
import nc.ui.pub.IFuncWindow;
import nc.ui.pub.ToftPanel;

public class ChangeUIUtil {
	private static IFuncWindow findOpenedWindow(String funcCode) {
		@SuppressWarnings("unchecked")
        List openModules = ClientEnvironment.getInstance().getOpenModules();
		@SuppressWarnings("unchecked")
        Iterator it = openModules.iterator();
        IFuncWindow window = null;
        while (it.hasNext()) {
            IFuncWindow tempWindow = (IFuncWindow) it.next();
            if (tempWindow.getFuncPanel().getModuleCode().equals(funcCode)) {
            	window = tempWindow;
            	break;
            }
        }
        return window;
    }
public static void changeUI(IworkflowLinkData dataVO,ToftPanel parent){
	IFuncWindow destUI = findOpenedWindow(dataVO.getDestFuncCode());
	IFuncWindow sourceUI = findOpenedWindow(dataVO.getSourceFuncCode());

	sourceUI.showWindow();
	parent.fireLinkEvent(null, IworkflowLinkData.Success);
	destUI.closeWindow();
}
}
